package deom11;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-04-16
 * Time: 8:58
 */
class ListNode{
    int val;
    ListNode next;
    public ListNode(int val){
        this.val = val;
    }
}
public class Test1 {
    public ListNode oddEvenList(ListNode head){
        if(head == null){
            return head;
        }
        //存放奇数位节点的链表
        ListNode oddlistNode = head;
        //存放偶数位节点的链表
        ListNode newlistNode =head.next;
        ListNode cur = newlistNode;
        while (cur != null && cur.next != null){
            oddlistNode.next = cur.next;
            oddlistNode = oddlistNode.next;
            cur.next = oddlistNode.next;
            cur = cur.next;
        }
        oddlistNode.next = newlistNode;
        return head;
    }
}
